<script setup>
    import {ref, watch} from "vue"
    const x = ref(0)
    // 设置侦听器观察其是否变化
    watch(x, (newVal, oldVal)=> {
      console.log(`${newVal/4*100}`+'%')
    })
</script>

<template>
<div class="outer">
  <div class="inner" :style="{width: `${x/4*100}`+'%'}">
    {{ `${x/4*100}`+'%' }}
  </div>
</div>
<br>
<button @click="x = 1">设置25%</button>
<button @click="x = 2">设置50%</button>
<button @click="x = 3">设置75%</button>
<button @click="x = 4">设置100%</button>
</template>

<style scoped>
  * {
    padding: 0;
    margin: 0;
  }
  .outer {
    width: 550px;
    height: 55px;
    border-radius: 2em;
    background-color: #2e0b0b;
    display: flex;
    align-items: center;
  }
  .inner {
    width: 50%;
    height: 51px;
    border-radius: 2em;
    margin: 0 2px;
    background-color: #106ec5;

    font-family: "幼圆";
    font-size: 24px;
    text-align: center;
    line-height: 45px;
    color: aliceblue;
  }
</style>